1. Field of the Invention
This invention relates to compiler optimizations for improving the performance of program code.
2. Background of the Invention
Memoization is a code optimization technique used to speedup functions that return the same value when provided the same parameters. To improve speed, a memoized function typically caches a result that is calculated for a specific set of inputs. Rather than recalculating the result upon receiving the same set of inputs, subsequent calls to the memoized function are configured to return the cached result. This eliminates or reduces the primary cost of a call with a specific set of inputs for all but the first call made to the function using the specific set of inputs.
Memoization can also be used to cause a request for an identical object to return the same object returned by prior requests. This form of memoization is also called “interning,” and permits object equivalence to be tested using object identity tests, which are typically less computationally intensive than equivalence tests comparing each of the object's fields. For example, Java's autoboxing feature for integers is designed to return the same Integer object for small integers near zero (e.g., integers between −128 and +127). Not only does this stop the proliferation of Integer objects for these common values, it also permits them to be compared using an object identity comparison (which is less computationally intensive) rather than comparing the object's fields (which is more computationally intensive).
Nevertheless memoization is not without its drawbacks. In some cases, memoized functions may actually hurt, as opposed to help, performance. For example, certain memoized functions may be unable to benefit from compiler optimizations, such as stack allocation and scalarization.
In view of the foregoing, what are needed are apparatus and methods to selectively remove memoizing logic that harms performance. Further needed are apparatus and methods to determine, using escape analysis, whether removing such memoizing functions is legal. Such apparatus and methods would ideally enable certain compiler optimizations, such as stack allocation and scalarization, to be more fully utilized.